package com.authine.cloudpivot.common.extension.customized.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.yundasys.hrcenter.dto.EmpRelatedInfoRespDTO;
import com.yundasys.hrcenter.dto.PcOrganizationInfoDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author saiwen
 * @date 2021/5/23 17:29
 * description kafka测试推送
 */
@RestController
@RequestMapping("/kafka")
@Slf4j
public class KafkaController {

    @Autowired
    KafkaTemplate<String, String> kafkaTemplate;

    @PostMapping("/send")
    public String sendKafkaMsg(@RequestBody String msg) {
        kafkaTemplate.send("test", msg);
        return "OK";
    }

    @PostMapping("/send/dept")
    public String sendKafkaDeptMsg(@RequestBody PcOrganizationInfoDTO organizationInfoDTO) {
        log.info("部门数据{}", JSONObject.toJSONString(organizationInfoDTO, SerializerFeature.WriteMapNullValue));
        kafkaTemplate.send("HR_ORG_TOPIC", JSON.toJSONString(organizationInfoDTO));
        return "dept";
    }

    @PostMapping("/send/emp")
    public String sendKafkaEmployeeMsg(@RequestBody EmpRelatedInfoRespDTO empRelatedInfoRespDTO) {
        log.info("人员数据{}", JSONObject.toJSONString(empRelatedInfoRespDTO, SerializerFeature.WriteMapNullValue));
        kafkaTemplate.send("HR_EMP_TOPIC", JSON.toJSONString(empRelatedInfoRespDTO));
        return "emp";
    }

}
